/* in.h is part of VIP program
 * Written by J. Salvador Arias, 2010
 *      CONICET, INSUE, Instituto Miguel Lillo,
 *      Miguel Lillo 205, S.M. de Tucuman (4000)
 *      Tucuman, Argentina
 *      e-mail: jsalarias@csnat.unt.edu.ar
 *
 * VIP is a free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public
 * License as published by the Free Software Foundation and
 * Creative Commons.
 *
 * This file and the VIP program is distributed in the hope
 * that it will be useful, but WITHOUT ANY WARRANTY; without
 * even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE.
 * See the GNU General Public License for more details.
 *
 * To view a copy of this license, visit
 * http://creativecommons.org/licenses/GPL/2.0/
 * or send a letter to
 * Creative Commons, 171 Second Street, Suite 300,
 * San Francisco, California, 94105, USA.
 */

#ifndef LOW_LEVEL_INPUT_HEADER_INCLUDED
#define LOW_LEVEL_INPUT_HEADER_INCLUDED

/* ------ Low level input ------ */
/* Structures and functions to control user generated flow (strings, numbers, etc.) */

#include "ghead.h"

typedef struct tagINSTREAM INSTREAM;

/* INSTREAM states */
#define OPEN_STREAM 1
#define EOF_REACHED 0

#define BAD_IN_FORMAT 2
#define END_CHAR_FOUND 4
#define END_OF_IN_LINE 8

/* Global reading modes */
#define READ_AS_IS 0
#define ALL_LOWER  1
SFLAG readingMode;

#define SETREADINGMODE(x) readingMode = (x)

/* Create and destroy a stream */
INSTREAM* CreateInStream ();
void DestroyInStream (INSTREAM* in);
void ResetInStream (INSTREAM* in);

/* Set the stream */
SFLAG SetInStreamToFile (INSTREAM* in, gchar* name);
SFLAG SetInStreamToString (INSTREAM* in, GString* src);

/* Reading the input */
SFLAG ReadString (INSTREAM* in, GString* dest);
SFLAG ReadStringUntil (INSTREAM* in, GString* dest, gchar end);
SFLAG PeekString (INSTREAM* in, GString* dest);
SFLAG ReadBoundComment (INSTREAM* in, GString* dest, gchar start, gchar end);
SFLAG ReadInt (INSTREAM* in, SINTEGER* number);
SFLAG ReadReal (INSTREAM* in, SREAL* number);
SFLAG ReadChar (INSTREAM* in, gchar* dest);

void SkipSpaces (INSTREAM* in);

/* ------ Type definitions ------ */

struct tagINSTREAM {
 gchar* stream;
 gchar* name;
 SCOUNTER actPos;
 SCOUNTER line;
 gsize len;
 SFLAG state;
 gchar nextChar;
};

#endif
